package leetcode.code0535;

import java.util.HashMap;
import java.util.Map;

public class Codec {
	Map<String, String> hash;

	int url;

	public Codec() {
		hash = new HashMap<>();
		url = 0;
	}

	// Encodes a URL to a shortened URL.
	public String encode(String longUrl) {
		String shortUrl = String.valueOf(url++);
		hash.put(shortUrl, longUrl);
		return shortUrl;
	}

	// Decodes a shortened URL to its original URL.
	public String decode(String shortUrl) {
		return hash.get(shortUrl);
	}
}
